package com.hqyj.lyf.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hqyj.lyf.mapper.UserMapper;
import com.hqyj.lyf.pojo.User;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;

/**
 * 专门用来跳转页面的控制器
 */
@Controller
public class SystemController {

    @Autowired
    private UserMapper userMapper;

    @GetMapping("/")
    public String login(){
        return "login";
    }

    @GetMapping("/unauthorized")
    public String unauthorized(){
        return "unauthorized";
    }

    @GetMapping("/index/{name}")
    public String index(@PathVariable("name") String name,Model model){
        System.out.println("-----------------------"+name);
        model.addAttribute("name",name);
        return "index";
    }

    // 退出登录
    @GetMapping("/logout")
    public String logout(){
        SecurityUtils.getSubject().logout();
        return "login";
    }

    // 欢迎页面
    @GetMapping("/welcome")
    public String welcome(){
        return "welcome";
    }

    // 考生列表 examinee-list
    @GetMapping("/examinee/examineeList")
    public String examineeList(){
        return "/examinee/examinee-list";
    }

    // 修改考生 examinee-edit
    @GetMapping("/examinee/examineeEdit/{userId}")
    public String examineeEdit(@PathVariable("userId") Integer userId, Model model){
        User user = userMapper.selectOne(new QueryWrapper<User>().eq("user_id", userId));
        model.addAttribute("user",user);
        return "/examinee/examinee-edit";
    }

    // 添加考生 examinee-add
    @GetMapping("/examinee/examineeAdd")
    public String examineeAdd(){
        return "/examinee/examinee-add";
    }




}
